<template>
	<view class="charts-box">
		<u-subsection :list="list" :current="current" @change="sectionChange" mode="subsection" keyName="label"
			activeColor="#2997ff"></u-subsection>
		<view style="padding: 10rpx 0;">
			<text style="font-size: 32rpx; color: #333; font-weight: bold;">成交客户行业分布分析</text>
		</view>
		<qiun-data-charts type="mount" :opts="opts" :chartData="chartData" />
	</view>
</template>

<script>
	import {
		selectOpenDoorSuccess
	} from '@/common/api/statistics.js'
	import {convertObjToArray} from '@/utils/util.js'
	export default {
		data() {
			return {
				list: [{
					label: ' 存款 ',
					value: 1
				}, {
					label: ' 贷款 ',
					value: 2
				}, {
					label: ' 保险 ',
					value: 3
				}, {
					label: ' 贵金属 ',
					value: 5
				}, {
					label: ' 收单 ',
					value: 4
				}],
				current: 0,
				customerLabel: 1,
				chartData: {},
				//您可以通过修改 config-ucharts.js 文件中下标为 ['mount'] 的节点来配置全局默认参数，如都是默认参数，此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式，达到页面简洁的需求。
				opts: {
					padding: [15, 15, 0, 5],
					enableScroll: false,
					legend: {
						itemGap:10,
						lineHeight:15
					},
					xAxis: {
						disabled: true

					},
					yAxis: {

						data: [{
							min: 0
						}]
					},
					extra: {
						mount: {
							type: "bar",
							widthRatio: 0.3,
							barBorderCircle: true,
							linearType: "custom",
							seriesGap: 20,


						}
					}
				}
			};
		},
		created() {
			this.getData()
		},
		methods: {
			async getData() {
				try {
					let res = await selectOpenDoorSuccess({
						customerLabel: this.customerLabel
					})
					this.getServerData(res.data);
				} catch (error) {
					//TODO handle the exception
				}
			},
			sectionChange(index) {
				this.current = index;
				this.customerLabel = this.list[index].value
				this.getData()
			},

			getServerData(data) {
				let res = {
					series: [{
						data: convertObjToArray(data)
					}]
				};
				this.chartData = JSON.parse(JSON.stringify(res));

			},


		}
	};
</script>

<style scoped>
	/* 请根据实际需求修改父元素尺寸，组件自动识别宽高 */
	.charts-box {
		width: 100%;
		padding: 24rpx;
		box-sizing: border-box;
		/* height: 300px; */
		background-color: #fff;
		margin-bottom: 24rpx;
	}
</style>